#ifndef DIRECTORYUTIL_H
#define DIRECTORYUTIL_H
#include "DXUT.h"
#include "DXUTmisc.h"
#define NUMSUBDIR 20
enum SUBDIRECTORY
{
	IODir = 0,
	ORGDATADIR,
	RENDERTECHDIR,
	SHADERSDIR,
	UTILITYDIR,
	MODELDIR,
	EMLIGHTDIR,
};

class CDirectoryUtil 
{
public:
	CDirectoryUtil()
	{
		m_strWorkDirectory = new TCHAR[MAX_PATH];
		memset(m_strWorkDirectory,0,sizeof(TCHAR)*MAX_PATH);

		m_strSubDirectoryArr.RemoveAll();
		for(int i = 0; i < NUMSUBDIR; i++)
		{
			TCHAR* tmpArr = new TCHAR[MAX_PATH];
			memset(tmpArr,0,sizeof(TCHAR)*MAX_PATH);
			m_strSubDirectoryArr.Add(tmpArr);
			
		}

	}
	~CDirectoryUtil()
	{
		SAFE_DELETE_ARRAY(m_strWorkDirectory);
		for(int i = 0; i < NUMSUBDIR; i++)
			SAFE_DELETE_ARRAY(m_strSubDirectoryArr[i]);		
		m_strSubDirectoryArr.RemoveAll();

	}
	void initSubDirectory(const TCHAR* pWorkDirectory)
	{
		swprintf(m_strWorkDirectory, pWorkDirectory);

		enum SUBDIRECTORY curDir = IODir;
		swprintf(m_strSubDirectoryArr[curDir],L"\\IO");
		
		curDir = ORGDATADIR;
		swprintf(m_strSubDirectoryArr[curDir],L"\\OrgData");

		curDir = RENDERTECHDIR;
		swprintf(m_strSubDirectoryArr[curDir],L"\\RenderTech");

		curDir = SHADERSDIR;
		swprintf(m_strSubDirectoryArr[curDir],L"\\Shaders");

		curDir = UTILITYDIR;
		swprintf(m_strSubDirectoryArr[curDir],L"\\Utility");

		curDir = MODELDIR;
		swprintf(m_strSubDirectoryArr[curDir],L"\\Models");

		curDir = EMLIGHTDIR;
		swprintf(m_strSubDirectoryArr[curDir],L"\\Models\\EM");

	}

	void GetAbsoluteFileFolder(const TCHAR* pFileName, enum SUBDIRECTORY curSubFolder, TCHAR* pAbsFileFolder, const unsigned int iSize = MAX_PATH)
	{
		if(m_strWorkDirectory == NULL)
		{
			printf("Please set up the work directory firstly!\n");
			return;
		}

		if(pAbsFileFolder == NULL)
		{
			printf("Please allocate memory for file name firstly!\n");
			return;
		}
		else
			memset(pAbsFileFolder,0,sizeof(TCHAR)*iSize);

		
		swprintf(pAbsFileFolder, L"%s", m_strWorkDirectory);
		wcscat(pAbsFileFolder, L"\\");
		wcscat(pAbsFileFolder, m_strSubDirectoryArr[curSubFolder]);
		wcscat(pAbsFileFolder, L"\\");
		wcscat(pAbsFileFolder, pFileName);
	}

public:
	TCHAR* m_strWorkDirectory;
	CGrowableArray<TCHAR*> m_strSubDirectoryArr;
};
#endif